package com.itstyle.quartz.kettleUtil;

import com.itstyle.quartz.entity.QuartzEntityLogsDt;
import com.itstyle.quartz.service.dao.IJobService;
import org.quartz.JobKey;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

public class LogUtil {

   public static void saveJobKettleLogs(String  KETTLEPATCH, String quartzid, JobKey jobkey, IJobService jobService,String status,String message){
       //处理日志信息
       QuartzEntityLogsDt quartzEntityLogsDt = new QuartzEntityLogsDt();
       quartzEntityLogsDt.setID(quartzid);
       quartzEntityLogsDt.setJOBKEY(jobkey.toString());
       quartzEntityLogsDt.setKETTLEPATCH(KETTLEPATCH);
       quartzEntityLogsDt.setBEGINTIME(DateUtil.getFormatTimeString(new Date(),"yyyy-MM-dd HH:mm:ss"));
       quartzEntityLogsDt.setSTATUS("执行中");
       quartzEntityLogsDt.setMESSAGE(message);

       jobService.saveJobKettleLogs(quartzEntityLogsDt);
   }

   public static void updateJobKettleLogs(String quartzid, JobKey jobkey, IJobService jobService,String status,String message){
       QuartzEntityLogsDt quartzEntityLogs = new QuartzEntityLogsDt();
       quartzEntityLogs.setENDTIME(DateUtil.getFormatTimeString(new Date(),"yyyy-MM-dd HH:mm:ss"));
       quartzEntityLogs.setSTATUS(status);
       quartzEntityLogs.setMESSAGE(message);
       jobService.updateJobKettleLogs(quartzEntityLogs,jobkey,quartzid);
   }

   public static String getLocalhostIp() throws UnknownHostException {
           InetAddress addr = InetAddress.getLocalHost();
           String hostIp = addr.getHostAddress();
           /*System.out.println("Local HostAddress: "+addr.getHostAddress());*/
           /* String hostName = addr.getHostName();
           System.out.println("Local host name: "+hostName);*/
           return hostIp;
   }

    public static void saveJobKettleLogs(String FILEPATCH,String  KETTLEPATCH, String quartzid, JobKey jobkey, IJobService jobService,String status,String message){
        //处理日志信息
        QuartzEntityLogsDt quartzEntityLogsDt = new QuartzEntityLogsDt();
        quartzEntityLogsDt.setID(quartzid);
        quartzEntityLogsDt.setJOBKEY(jobkey.toString());
        quartzEntityLogsDt.setKETTLEPATCH("KETTLEPATCH:"+KETTLEPATCH+"& FILEPATCH:"+FILEPATCH);
        quartzEntityLogsDt.setBEGINTIME(DateUtil.getFormatTimeString(new Date(),"yyyy-MM-dd HH:mm:ss"));
        quartzEntityLogsDt.setSTATUS("执行中");
        quartzEntityLogsDt.setMESSAGE(message);

        jobService.saveJobKettleLogs(quartzEntityLogsDt);
    }

}
